package com.derbysoft.dswitch.adapter.ihg.webservice.protocal_test;

import com.derbysoft.dswitch.adapter.ihg.common.utils.LogUtils;
import com.derbysoft.dswitch.adapter.ihg.dto.*;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.util.StopWatch;

/**
 * User: jason
 * Date: 12-4-19
 */
public class InterfaceTest extends BaseTest<Request, Response> {
    private static final Log LOGGER = LogFactory.getLog(InterfaceTest.class);
    private static final String URL = "http://support.derbysoft.com/dmx/redirect.ci?Redirect-URL=http://utc.b2b.ihg.com/b2b/xml/sprravailsearch/2006A/hotels.xml";
    private static final String RESERVATION_URL = "http://support.derbysoft.com/dmx/redirect.ci?Redirect-URL=http://utc.b2b.ihg.com/b2b/xml/makereservation/2006A/hotels.xml";
    private static final String CANCEL_URL = "http://support.derbysoft.com/dmx/redirect.ci?Redirect-URL=http://utc.b2b.ihg.com/b2b/xml/cancelreservation/2006A/hotels.xml";

    public static void main(String[] args) {
        InterfaceTest getHotelAvailTest = new InterfaceTest();
        getHotelAvailTest.invokeAvail();
    }

    public void invokeAvail() {
        StopWatch stopWatch = new StopWatch();
        stopWatch.start();
        OTAHotelAvailRQ request = (OTAHotelAvailRQ) JaxbUtils.unmarshal(sampleXml("DS2_RQ_01.xml"), MARSHALLER);
        OTAHotelAvailRS otaHotelAvailRS = (OTAHotelAvailRS) send(URL, request);
        stopWatch.stop();
        LOGGER.info(LogUtils.toXML(otaHotelAvailRS));
    }

    public void printAvailRS(){
        OTAHotelAvailRS response = (OTAHotelAvailRS) JaxbUtils.unmarshal(sampleXml("OTA_AvailRS.xml"), MARSHALLER);
        LOGGER.info(response);
    }

    public void invokeReservation() {
        OTAHotelResRQ request = (OTAHotelResRQ) JaxbUtils.unmarshal(sampleXml("OTA_HotelResRQ.xml"), MARSHALLER);
        OTAHotelResRS otaHotelAvailRS = (OTAHotelResRS) send(RESERVATION_URL, request);
        LOGGER.info(LogUtils.toXML(otaHotelAvailRS));
    }

    public void invokeModifyReservation() {
        OTAHotelResRQ request = (OTAHotelResRQ) JaxbUtils.unmarshal(sampleXml("OTA_HotelResModifyRQ.xml"), MARSHALLER);
        OTAHotelResRS otaHotelAvailRS = (OTAHotelResRS) send(RESERVATION_URL, request);
        LOGGER.info(LogUtils.toXML(otaHotelAvailRS));
    }

    public void invokeCancellation() {
        OTACancelRQ cancelRQ = (OTACancelRQ) JaxbUtils.unmarshal(sampleXml("OTA_CancelRQ.xml"), MARSHALLER);
        OTACancelRS otaHotelAvailRS = (OTACancelRS)send(CANCEL_URL, cancelRQ);
        LOGGER.info(LogUtils.toXML(otaHotelAvailRS));
    }
}
